package com.xuan.webwork.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.xuan.webwork.entitys.Teacher;

import java.util.List;
import java.util.Optional;

@Repository
public interface TeacherRepository extends JpaRepository<Teacher, Long> {
    
    // 根据教师编号查找教师
    Optional<Teacher> findByTeacherId(String teacherId);
    
    // 根据姓名模糊查找教师
    List<Teacher> findByNameContaining(String name);
    
    // 根据部门查找教师
    List<Teacher> findByDepartment(String department);
    
    // 检查教师编号是否存在
    boolean existsByTeacherId(String teacherId);
    
    // 根据教师编号删除教师
    void deleteByTeacherId(String teacherId);
    
    // 自定义查询：根据多个条件查找教师
    @Query("SELECT t FROM Teacher t WHERE " +
           "(:name IS NULL OR t.name LIKE %:name%) AND " +
           "(:department IS NULL OR t.department = :department) AND " +
           "(:title IS NULL OR t.title = :title)")
    List<Teacher> findTeachersByConditions(@Param("name") String name, 
                                         @Param("department") String department, 
                                         @Param("title") String title);
}
